package artibella.media 
{
	import artibella.IDisposable;
	import artibella.IStageObserver;
	import artibella.media.controls.AController;
	
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class APlayer extends Sprite implements IDisposable, IStageObserver
	{

		protected var _view:Sprite;
		protected var _controller:AController;
		protected var _list:AList;	
		
		protected var _defaultVolume:Number;
		
		
		public function APlayer() 
		{
			_init();
		}
		
		protected function _init():void
		{
			_view = new Sprite();
			addChild( _view );
			
			_defaultVolume = .7;
		}
		
		// - - -
		
		public function set controller( c:AController ):void
		{
			_controller = ( c != null ) ? c : new AController();
			_controller.player = this;
			_controller.init();
			_view.addChild( _controller );
		}
		
		public function get controller():AController
		{
			return _controller;
		}
		
		// - - -
		
		public function get list():AList
		{
			return _list;
		}
		
		public function set list( l:AList ):void
		{
			_list = l;
		}
		
		public function addListItem( u:String, t:String = "", p:String = "" ):void
		{
			if ( _list == null ) _list = new AList( true );
			
			_list.addItem( new AListItem( u, t ) );
		}

		// - - -

		public function previous():void
		{
			var item:AListItem = _list.getPreviousItem();
		}
		
		public function next():void
		{
			var item:AListItem = _list.getNextItem();
		}
		
		// - - -
		
		public function play( i:int = -1 ):void
		{
			if ( _list == null ) {
				//throw new Error( "APlayer -- no AListItem added" );
				trace(" ");
				trace("APlayer -- no AListItem added to the list");
				return;
			}
			
			var item:AListItem = ( i >= 0 ) ? _list.getItemByIndex( i ) : _list.getNextItem();
		}
		
		public function stop():void
		{
			// override
		}
		
		public function pause():void
		{
			// override
		}
		
		
		public function set defaultVolume( n:Number ):void
		{
			_defaultVolume = n;
		}
		
		// ----- IStageObserver
		
		public function stageUpdate( w:int, h:int ):void 
		{
			// override
		}
		
		// ----- IDisposable
		
		public function dispose():void
		{
			_controller = null;
		}
	}

}